package it.mauriziobasile.dietarapida.gui.tablemodels;


import java.awt.Color;
import java.awt.Component;
import java.awt.Font;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author Maurizio Basile
 */
public class AlimentiCellRenderer extends DefaultTableCellRenderer {

    private static final long serialVersionUID = 5273181173481233495L;
    private Color[] colors;
    private String[] pasti;
    private String ppasti;
    private Font defFont;
    private Color defColor;

    public AlimentiCellRenderer() {
        super();
        colors = new Color[6];
        colors[0] = Color.cyan;
        colors[1] = Color.yellow;
        colors[2] = Color.magenta;
        colors[3] = Color.orange;
        colors[4] = Color.green;
        colors[5] = Color.white; //PER LA RIGA DI SEPARAZIONE TRA I PASTI

        pasti = new String[5];
        pasti[0] = "Colazione";
        pasti[1] = "Spuntino";
        pasti[2] = "Pranzo";
        pasti[3] = "Merenda";
        pasti[4] = "Cena";
        ppasti="";
        for (int i=0;i<5;i++)
            ppasti=ppasti+"  "+pasti[i];

        defColor=Color.white;
        //defFont=resourceMap.getFont("jTableMeals.font");
        setHorizontalAlignment(CENTER);
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        cell.setFont(defFont);
     
        cell.setBackground(defColor);
        AlimentiTableModel atm = (AlimentiTableModel) table.getModel();
        try {
            int pasto = atm.row2MealId(row);
            cell.setBackground(colors[pasto]);
            //if(ppasti.contains(value.toString()))
            if (atm.isAMealRow(row))
                cell.setFont(defFont.deriveFont(java.awt.Font.BOLD, defFont.getSize()+1));
            if(atm.isATotalRow(row))
                cell.setFont(defFont.deriveFont(java.awt.Font.ITALIC, defFont.getSize()+1));

            // You can also customize the Font and Foreground this way
            // cell.setForeground();
            // cell.setFont();

        } catch (Exception e) {
        }
        return cell;
    }

}
